# TODO: Add comment
# 
# Author: broken
###############################################################################
library(raster)
library(base)
library(gstat)

inputpath= "/home/phamha/Desktop/b.tif"
shape_file = "/home/phamha/BDNEN/VNM_adm0.shp"
shap=shapefile(shape_file)

rasterFile=raster(inputpath)
plot(rasterFile)

rasterFile3=mask(rasterFile,shap)
plot(rasterFile3)










listFile = list.files(path = inputpath,pattern="CB_10km.tif$",full.names = TRUE,recursive=TRUE)
listSize=length(listFile)

for (i in 1:listSize) {
	rasterFile=raster(listFile[i])
	rasterFile=crop(rasterFile,shap)
	rasterFile=mask(rasterFile,shap)
	
	outFile=paste(substr(listFile[i],1,146),"_mask.tif",sep="")
	writeRaster(rasterFile,filename=outFile,format="GTiff")
	print(outFile)
}


